SpotCheck Logo

Type Conflicts

SpotCheck has complete information about the types of Java expressions, and uses this information to provide feedback about type conflicts. For example, in the following project, the spot immediately to the right of the assignment operator ("=") indicates a violation of Java's rules for assignment compatibility.

In this case, the type of "intx + longx" is long, which cannot be assigned to an int, the type of the left-hand side. Note that the user can eliminate the error in any of several ways, say by changing the declaration of "intx" to read "long intx = 0", or by changing the declaration of "longx" in the opposite way. Regardless of how it is accomplished, the instant that the error is fixed, the spot goes away.

SpotCheck is a work in progress, and does not yet implement all of the possible expression type constraints. However, as of this writing, most of the commonest expressions are checked, including assignment, binary arithmetic, and relational expressions.

In this example, the user is attempting to compare an Exception with an int. Since Exception is a reference type, it is certainly not numeric.

Note that the position of the spot conveys a hint of the problem. If the spot were immediately to the left of "exx", it would indicate that "exx" could not be resolved for one reason or another. If the spot were adjacent to the ">" operator, it would indicate that both participating sub-expressions were equally at fault for the error. However, the spot position to the right of "exx" indicates a problem with the type of "exx" in this context. In general, SpotCheck consistently follows this rule of thumb when positioning spots, and thereby conveys as much information as possible with spot placement.

© 1997 GenieWorks, LLC. All rights reserved